Skip to content

Apply Rector: CountArrayToEmptyArrayComparisonRector - #3839

Merged
samsonasik merged 1 commit into
developfrom
apply-rector-count-array-to-empty-array-comparison
Oct 30, 2020
Merged

Apply Rector: CountArrayToEmptyArrayComparisonRector#3839
samsonasik merged 1 commit into
developfrom
apply-rector-count-array-to-empty-array-comparison

Conversation

@samsonasik

Copy link
Copy Markdown
Member

Change count array comparison to empty array comparison to improve performance

Checklist:

  • Securely signed commits

Change count array comparison to empty array comparison to improve performance
@samsonasik

Copy link
Copy Markdown
Member Author

All green 🎉

@paulbalandan paulbalandan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this trend in some repo. Is this check also more performant than truthy checks? I mean if if ($array !== [] is faster than if ($array)?

@samsonasik

Copy link
Copy Markdown
Member Author

Checked benchmark with 1000000 at https://phpsandbox.io/n/cool-limit-q2mg seems sometime faster, sometime slower, or same.

Tested locally, compare with $array !== [] is 2x faster.

paulbalandan
paulbalandan approved these changes Oct 30, 2020
@samsonasik
samsonasik merged commit cb31d01 into develop Oct 30, 2020
@samsonasik
samsonasik deleted the apply-rector-count-array-to-empty-array-comparison branch October 30, 2020 19:29
@samsonasik

Copy link
Copy Markdown
Member Author

@paulbalandan thank you for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants